home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 7_10.lha / 7_10 / p_restore.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  2KB  |  52 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <process.h>
  6. include <debug.h>    /* DELETE */
  7. include <stackdir.h>
  8. / Restore a process to be the current process.
  9. / It doesn't return but instead comes back
  10. / through contextswitch(). It works by memcpy()'ing the
  11. / process' copy of the stack into the real stack.
  12. / First adjust the stack to make certain that
  13. / we are above that which needs to be restored.
  14. / This is done by recursively invoking restore().
  15. tatic void restorestack(char *lowerbound, char *from,
  16.    unsigned size, jmp_buf jb)
  17.  
  18.    memcpy(lowerbound, from, size);
  19.    longjmp(jb, 1);
  20.    /* NOTREACHED */
  21.  
  22.  
  23. oid process::restore()
  24.  
  25.    char x;
  26.    char *px = &x;
  27.    if (debug)    /*DELETE*/ cerr << "process" << this << "::restore()\n";
  28.    if (debug)    /*DELETE*/ cerr << "\tgrows_up == " << Stackdir.grows_up() << "\n";
  29.    if (debug)    /*DELETE*/ cerr << "\t&x = ";
  30.    if (debug>1)/*DELETE*/ cerr << form("%#x", px);
  31.    if (debug)    /*DELETE*/ cerr << "\n";
  32.    if (debug)    /*DELETE*/ cerr << "\tt_stackbase = ";
  33.    if (debug>1)/*DELETE*/ cerr << form("%#x", t_stackbase);
  34.    if (debug)    /*DELETE*/ cerr << "\n";
  35.    if (debug)    /*DELETE*/ cerr << "\tt_stacksize = " << t_stacksize << "\n";
  36.  
  37.    // if necessary, bump up the stack size
  38.    int diff = Stackdir.diff(px, t_stackbase);
  39.    if (debug) /*DELETE*/ cerr << "\tpx - t_stackbase = " << diff << "\n";
  40.    if (diff < t_stacksize)
  41. restore();
  42.  
  43.    // restore the stack
  44.    char *lowerbound = Stackdir.grows_up() ?
  45.            t_stackbase :
  46.                   t_stackbase - t_stacksize;
  47.    t_thisprocess = this;
  48.    if (debug) /*DELETE*/ cerr << "<<<< process" << this << "::restore()\n";
  49.    restorestack(lowerbound, t_stack, t_stacksize, t_jb);
  50.    /* NOTREACHED */
  51.  
  52.